package org.naigu.peach.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.naigu.peach.biz.ReplyBiz;
import org.naigu.peach.dal.dao.ReplyDAO;
import org.naigu.peach.dal.dataobject.ReplyDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class ReplyBizImpl implements ReplyBiz{

    private final static Logger logger = LoggerFactory.getLogger(ReplyBizImpl.class);

    @Autowired
    private ReplyDAO replyDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            ReplyDO replyDO = replyDAO.getReplyById(id);
            bizResult.data.put("replyDO", replyDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Reply error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = replyDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<ReplyDO> replyList = replyDAO.selectForPage(baseQuery);
            bizResult.data.put("replyList", replyList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Reply list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            replyDAO.delReplyById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete reply error", e);
        }
        return bizResult;
    }

    public BizResult create(ReplyDO replyDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = replyDAO.insert(replyDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Reply error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(ReplyDO replyDO) {
        BizResult bizResult = new BizResult();
        try {
            replyDAO.updateByIdSelective(replyDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update Reply error", e);
        }
        return bizResult;
    }


}
